package pm;

public class StudentManagement implements StudentMange,StudentMange2 {
    @Override
    public void test() {

    }

    @Override
    public void printInfo2(Student[] students) {
        for (Student student : students) {
            System.out.println(student);
        }
    }

    @Override
    public void printAvgScore2(Student[] students) {
        double sum = 0;
        for (Student student : students) {
            sum += student.getScore();
        }
        System.out.println(sum / students.length);
    }

    @Override
    public void printInfo(Student[] students) {
        for (Student student : students) {
            System.out.println(student);
        }
        int maleCount = 0;
        int femaleCount = 0;
        for (Student student : students) {
            if (student.getGender() == '男') {
                maleCount++;
            } else if (student.getGender() == '女') {
                femaleCount++;
            }
        }
        System.out.printf("男生人数：%d, 女生人数%d", maleCount, femaleCount);
        System.out.println();
    }

    @Override
    public void printtAvgScore(Student[] students) {
        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0; j < students.length - i - 1; j++) {
                if (students[j].getScore() > students[j + 1].getScore()) {
                    Student stu = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = stu;
                }
            }
        }
        double sum = 0;
        for (int i = 0; i < students.length; i++) {
            sum += students[i].getScore();
        }
        System.out.println(sum / (students.length - 1));
    }
}
    class Test {

        public static void main(String[] args) {
            Student stu1 = new Student("张三", '男', 90);
            Student stu2 = new Student("李四", '男', 81);
            Student stu3 = new Student("王五", '女', 72);
            Student stu4 = new Student("赵六", '女', 61);
            Student[] students = {stu1, stu2, stu3, stu4};

            StudentManagement stuM = new StudentManagement();
            StudentMange studentMange = stuM;
            studentMange.printInfo(students);
            studentMange.printtAvgScore(students);

            StudentMange2 studentMange2 = stuM;
            studentMange2.printAvgScore2(students);
            studentMange2.printInfo2(students);

            StudentMange2.test01();
        }
    }